#include "testdemo.h"
#include <QDebug>
#include <unistd.h>
#include "mydialog.h"

TestDemo::TestDemo(QObject *parent)
    : QObject(parent)
{
    m_demoInterface = new ComBobbiDemoDbusInterface("com.bobbi.demo", "/com/bobbi/demo", QDBusConnection::sessionBus(), this);
    connect(m_demoInterface, SIGNAL(send_add_request(int, int)), this, SLOT(add_request_slot(int,int)));

    int r = m_demoInterface->test_add(1, 2);
    qDebug() << " 1 + 2 = " << r;

    m_demoInterface->setVersion("v12345");

    QString version = m_demoInterface->getVersion();
    qDebug() << "get version is " << version;

    QEventLoop e;
    e.exec();
}

void TestDemo::add_request_slot(int a, int b)
{
#if 0
    qDebug() << "receice a send_add_request " << a << " + " << b;
    sleep(5);
    m_demoInterface->Call();
#else
    MyDialog d;
    connect(&d, &MyDialog::finished, this, [&](int r) {
        m_demoInterface->Call(r);
    });
    d.exec();
#endif
}
